package cn.jhc.social.qq.api.impl;

import java.net.URI;

import org.springframework.web.client.RestTemplate;

import cn.jhc.social.qq.api.UserInfo;
import cn.jhc.social.qq.api.UserOperations;

class UserTemplate extends AbstractQQOperations implements UserOperations {
	
	private final RestTemplate restTemplate;
	private final QQTemplate qqTemplate;

	public UserTemplate(QQTemplate qqTemplate, boolean isAuthorized) {
		super(isAuthorized);
		this.qqTemplate = qqTemplate;
		this.restTemplate = qqTemplate.getRestTemplate();
	}

	@Override
	public UserInfo getUserProfile() {
		requireAuthorization();
		return getUserProfile(qqTemplate.getOpenid());
	}
	
	@Override
	public UserInfo getUserProfile(String openid) {
		URI uri = buildUri("user/get_user_info", "openid", openid);
		return restTemplate.getForObject(uri, UserInfo.class);
	}

}
